<!-- 体尺测定添加 -->
<template>
  <el-button @click="beginAdd()" type="danger" style="margin-top: 10px;">+新增</el-button>
  <el-button @click="save()" type="danger" style="margin-top: 10px;">保存</el-button>
  <el-button @click="cancel()" type="danger" style="margin-top: 10px;">撤销</el-button>
  <el-button @click="delBegin()" type="danger" style="margin-top: 10px;">删除</el-button>
  <hr style="margin-top: 10px;">
    <el-row style="margin-top: 20px;" >
        <el-col :span="8" style="margin-left: 30px">
          测定日期：<el-date-picker
        v-model="form.bodyMeanDate"
        type="date"
        placeholder="Pick a date"
        :default-value="new Date()"
        style="width: 200px;"
      />
        </el-col>
        <el-col :span="8" style="margin-left: 14px" >
          羊只耳号：       
        <el-select  placeholder="请选择羊只耳号" v-model="form.earNumber" style="width: 200px">
          <el-option v-for="item in EarData" :label="item.earNumber" :value="item.earNumber" />
        </el-select>
      
        </el-col>
    </el-row>
    <el-row style="margin-top: 20px;" >
        <el-col :span="8" style="margin-left: 30px">
          身高(cm)：<el-input style="width: 200px;" v-model="form.bodyTall" placeholder="请输入身高"></el-input>
        </el-col>
        <el-col :span="8" style="margin-left: 16px">
          体长(cm)：<el-input style="width: 200px;" v-model="form.bodyLength" placeholder="请输入体长"></el-input>
        </el-col>
    </el-row>
    <el-row style="margin-top: 20px;" >
        <el-col :span="8" style="margin-left: 30px">
          胸围(cm)：<el-input style="width: 200px;" v-model="form.bodyBust" placeholder="请输入胸围"></el-input>
        </el-col>
        <el-col :span="8" style="margin-left: 16px">
          管围(cm)：<el-input style="width: 200px;" v-model="form.bodyPipe" placeholder="请输入管围"></el-input>
        </el-col>
    </el-row>
    <el-row style="margin-top: 20px;" >
        <el-col :span="8" style="margin-left: 16px">
          阴囊围(cm)：<el-input style="width: 200px;" v-model="form.bodyScrotal" placeholder="请输入阴囊围"></el-input>
        </el-col>
        <el-col :span="8">
          背膘厚度(cm)：<el-input style="width: 200px;" v-model="form.bodyBackfat" placeholder="请输入背膘厚度"></el-input>
        </el-col>
    </el-row>
    <el-row style="margin-top: 20px;" >
        <el-col :span="8">
          眼肌面积(cm)：<el-input style="width: 200px;" v-model="form.eyeArea" placeholder="请输入眼肌面积"></el-input>
        </el-col>
        <el-col :span="8" style="margin-left: 16px">
          眼肌宽度(cm)：<el-input style="width: 200px;" v-model="form.eyeWidth" placeholder="请输入眼肌宽度"></el-input>
        </el-col>
    </el-row>

</template>
<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue';
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
import { ElTable } from 'element-plus';
import { ElMessage, ElMessageBox } from 'element-plus';
const router = useRouter();
const route = useRoute();

const form=reactive({
  bodyMeanDate:new Date(),
  earNumber:'',
  bodyTall:'',
  bodyLength:'',
  bodyBust:'',
  bodyPipe:'',
  bodyScrotal:'',
  bodyBackfat:'',
  eyeArea:'',
  eyeWidth:''
})
//羊只耳号下拉框
const EarData:any=ref([])
const getEarData=()=>{
  axios.get('http://localhost:5039/api/SleepBegin/SelectEar').then(res=>{
    console.log(res)
    EarData.value=res.data.item
  })
}

//添加
const save=()=>{
  axios.post('http://localhost:5039/api/SleepWeight/AddBodyMean',form).then(res=>{
     console.log(res)
     if(res.data.code>0){
      ElMessage.success('添加成功')
     }else if(res.data.code==-1){
      ElMessage.error('该耳号信息已添加')
     }
  })
}
//撤销
const cancel=()=>{

  form.earNumber='',
  form.bodyTall='',
  form.bodyLength='',
  form.bodyBust='',
  form.bodyPipe='',
  form.bodyScrotal='',
  form.bodyBackfat='',
  form.eyeArea='',
  form.eyeWidth=''
}
//新增
const beginAdd=()=>{
  axios.post('http://localhost:5039/api/SleepWeight/AddBodyMean',form).then(res=>{
     console.log(res)
     if(res.data.code>0){
      ElMessage.success('添加成功')
      cancel()
     }
  })
}


onMounted(()=>{
  getEarData()
})
</script>